<template>
  <div id="app">
    <!-- 顶部导航 -->
    <Topbar :key="topbarkey" />
    <!-- 头部nav链接 -->
    <Header />
    <router-view />
    <!-- 底部公共部分 -->
    <Footer />
    <Login v-show="isShowLoginModal" />
    <!-- 提示框 -->
    <transition name="slide">
      <Toast v-show="isShowToast" />
    </transition>
  </div>
</template>
<script>
import Topbar from "@/components/Topbar.vue";
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
import Login from "@/components/Login.vue";
import Toast from "@/components/Toast.vue";
// 因为JingPinAPI是一个值，要对象的形式在这里展示，所以要加{}
import { JingPinAPI } from "@/request/api.js";
import { mapState } from "vuex";
export default {
  data() {
    return {
      topbarkey: "",
    };
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        this.topbarkey++;
        
      },
    },
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModel.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  async created() {
    /* 
      可优化点
      1.请求时，每一次都需要手动填入域名http://192.168.113.249:8081/cms
      /products/recommend 如果接口地址发生变化。有几个地方调用就需要改几个组件
      【统一设置请求地址。统一管理所有接口地址】
      2.每次都需要手动的携带token 【拦截器】
      3.如果a完成后才能请求b时 【async + await】
    */

    //   this.$axios.get("http://192.168.113.249:8081/cms/products/recommend").then((res)=>{
    //     console.log("res",res);
    //   })

    // request.get('/products/recommend').then((res)=>{
    //   console.log("res1",res);
    // })

    //JingPinAPI(),配合api.js才不会出现一个页面显示全部接口内容
    // JingPinAPI().then((res) => {
    //   console.log("res2", res);
    // });

    let res = await JingPinAPI();
    console.log("res", res);
  },
};
</script>


<style lang="less">
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
